<?php
declare (strict_types = 1);

namespace app\db;

use think\facade\Db;
use think\Model;
use app\model\User;

class UserDb
{

    
    /**
     * 执行服务
     *
     * @return mixed
     */
    public function findone()
    {

        $user = new User();
        $userdata = [
            'name' => '张三',
            'age' => 88
        ];
        //本来这里是访问DB
//        $arr['a']= 11;
//        $arr['b']= 22;
//        return $arr;
        //todo 换成db
        //Db::query("select * from blog_user where status=:id", ['id' => 1]);
        //Db::query("select * from blog_user");
        //$sql = "INSERT INTO `blog_user` VALUES ('蜡笔小新', 18)";
        //var_dump(Record::getLastSql()); // 获取SQL语句
        //Db::execute($sql);

        $result = \think\facade\Db::query('SELECT * FROM `blog_user`');
        //$result = \think\facade\Db::execute('INSERT INTO `blog_user`("name","age") values("luo",18)');
        //$result = \think\facade\Db::execute('SELECT * FROM `blog_user`("name","age") values("luo",18)');
        //$affectedRows = \think\facade\Db::execute('UPDATE `blog_user` SET `age` =99  WHERE `id` = 1');
        $result = $user->save($userdata);
        $arr['a']= 11;
        $arr['b']= 22;
        //$arr['c']= $result;
        //$arr['d']= $affectedRows;
        //var_dump(Record::getLastSql()); // 获取SQL语句
        return $arr;
    }
}
